import Vue from "vue";
import VueRouter from "vue-router";
import Login from "@/components/portal/Login";
// import MagHome from "@/components/MagHome";
// import LoginStu from "@/components/student/LoginStu";
// import Student from "@/components/student/Student";
// import JuheWeather from "@/components/weather/JuheWeather";
import Denglu from "@/components/denglu/Denglu";
import yemian from "@/components/yemian/Yemian";

import student from '@/components/student/Student';
import yuangong from '@/components/yuangong/Yuangong';
import classroom from '@/components/classroom/Classroom';
import class1 from '@/components/class/Class';
import dormitory from '@/components/dormitory/Dormitory';
import apache from '@/components/apache/Apache';
import axios from "@/components/axios/Axios";
import commodity from "@/components/commodity/commodity";
Vue.use(VueRouter);

// 公共路由
export const constantRoutes = [
  {
    path: "/commodity",
    name: commodity,
    component: commodity,
  },

  {
    path: "/login",
    name: Login,
    component: Login,
  },
  {
    path: "/denglu",
    name: Denglu,
    component: Denglu,
  },
  {
    path: "/student",
    name: student,
    component: student,
  },
  
  {
    path: "/yuangong",
    name: yuangong,
    component: yuangong,
  },
  {
    path: "/classroom",
    name: classroom,
    component: classroom,
  },
  {
    path: "/class",
    name: class1,
    component: class1,
  },
  {
    path: "/dormitory",
    name: dormitory,
    component: dormitory,
  },
  
  {
    path: "/yemian",
    name: yemian,
    component: yemian,
    //子路由
    children: [
      {
        path: "student",    // 相对路径 学生
        // name: "denglu",    
        component: () => import('@/components/student/Student')
      },
      {
        path: "yuangong",    // 相对路径 员工
        // name: "denglu",    
        component: () => import('@/components/yuangong/Yuangong')
      }, 
      {
        path: "classroom",    // 相对路径 教室
        // name: "denglu",    
        component: () => import('@/components/classroom/Classroom')
      },
      {
        path: "class",    // 相对路径 班级
        // name: "denglu",    
        component: () => import('@/components/class/Class')
      },
      {
        path: "dormitory",    // 相对路径 班级
        // name: "denglu",    
        component: () => import('@/components/dormitory/Dormitory')
      },
      {
        path: "apache",    // 相对路径 echarts
        // name: "denglu",    
        component: () => import('@/components/apache/Apache')
      },
      {
        path: "examPlace",    // 相对路径 echarts
        // name: "denglu",    
        component: () => import('@/components/examPlace/ExamPlace')
      },
      {
        path: "examPlan",    // 相对路径 echarts
        // name: "denglu",    
        component: () => import('@/components/examPlace/ExamPlan')
      },
      {
        path: "examSubject",    // 相对路径 echarts
        // name: "denglu",    
        component: () => import('@/components/examPlace/ExamSubject')
      },
    ],
  },
  {
    path: "/axios",
    name: axios,
    component: axios,
  },
  {
    path: "/apache",
    name: apache,
    component: apache,
  },
  /*
  {
    path: "/",
    name: Login,
    component: Login,
  },
  {
    path: "/maghome",
    name: MagHome,
    component: MagHome,
  },

  {
    path: "/student",
    name: Student,
    component: Student,
    children: [
      {
        path: "loginstu",    // 相对路径
        name: LoginStu,
        component: () => import('@/components/student/LoginStu')
      },
    ],
  },
  {
    path: "/loginStu",
    name: LoginStu,
    component: LoginStu,
    // component: () => import('@/components/stu/LoginStu')
  },
  */
  /**
  {
    path: "/juheWeather",
    name: JuheWeather,
    component: JuheWeather,
  },
   */

];


//登陆
const router =  new VueRouter({
  mode: "history", // 后台服务器也要做相关配置 https://v3.router.vuejs.org/zh/guide/essentials/history-mode.html#%E5%90%8E%E7%AB%AF%E9%85%8D%E7%BD%AE%E4%BE%8B%E5%AD%90
  routes: constantRoutes,
});
//登陆
router.beforeEach((to, from, next) => {
  // console.log("to::::" + JSON.stringify(to));
  console.log("00000")
  if(sessionStorage.getItem("key") != null || to.name.name == 'Denglu'){
    console.log("111111")
    next();

  }else{
    console.log("222222");
    next("/denglu")
  }
})



export default router;
